<!DOCTYPE html>
<html lang="zh">
<head>
    <title>用户登录</title>
    <meta name="description" content="xinsite快速开发">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="javascript/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="javascript/plugins/assets/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="javascript/plugins/assets/css/checkbox.css" rel="stylesheet">

    <link rel="stylesheet" href="javascript/plugins/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="javascript/plugins/assets/css/ace-rtl.min.css"/>
    <link rel="stylesheet" href="javascript/plugins/assets/css/ace-skins.min.css"/>
    <link rel="stylesheet" href="styles/login_01.css"/>

    <script src="javascript/common/constant.js" type="text/javascript"></script>
    <script src="javascript/plugins/jquery/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script src="javascript/plugins/assets/layer/layer.js" type="text/javascript"></script>
    <script src="javascript/plugins/encrypt/md5.js" type="text/javascript"></script>
    <script src="javascript/plugins/encrypt/jsencrypt.js" type="text/javascript"></script>
    <script src="javascript/plugins/jquery/jquery.cookie.js" type="text/javascript"></script>
    <link rel="icon" href="images/favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
    <link rel="bookmark" href="images/favicon.ico" type="image/x-icon" />
</head>
<body class="login-layout">
<div class="logintop">
    <span>在线体验，用户名 admin，密码 111111</span>
    <ul>
        <li><a href="#">用户注册</a></li>
        <li><a href="#">帮助</a></li>
        <li><a href="#">关于</a></li>
    </ul>
</div>
<div class="loginbody">
    <div class="login-container">
        <div class="center" id="top_title" style="margin-top: 160px;">
            <h1>
                <i class="icon-leaf green"></i><span class="orange">快速开发</span>
                <span style="font-size:24px;" class="white">XinSite 演示系统</span>
            </h1>
            <h4 class="white">
                XinSite Code Demo System</h4>
        </div>
        <div class="space-6">
        </div>
        <div class="position-relative">
            <div id="login-box" class="login-box widget-box no-border visible">
                <div class="widget-body">
                    <div class="widget-main">
                        <h4 class="header blue lighter bigger">
                            <i class="icon-coffee green"></i>用户登录
                        </h4>
                        <div class="login_icon">
                            <img src="images/login_01/login.png"/></div>
                        <form class="">
                            <fieldset>
                                <label class="block clearfix">
                                    <span class="block input-icon input-icon-right">
                                        <input style="display: none">
                                        <input type="text" id="username" tabindex="1" class="form-control"
                                               placeholder="登录名" name="username"/>
                                        <i class="icon-user"></i></span>
                                </label>
                                <label class="block clearfix">
                                    <span class="block input-icon input-icon-right">
                                        <input type="password" id="password" tabindex="2" class="form-control"
                                               placeholder="密码" name="password"/>
                                        <i class="icon-lock"></i></span>
                                </label>
                                <div class="clearfix">
                                    <label class="inline">
                                        <input type="text" id="validCode" tabindex="3" class="form-control"
                                               style="width: 90px;height: 32px;"
                                               placeholder="验证码" name="验证码"/>
                                    </label>
                                    <label class="inline">
                                        <img id="captcha_img" class="validCodeImg" title="看不清，点击图片刷新"
                                             onclick="changeVerifyCode(this)" src="imageKaptcha" alt="验证码"
                                             style="margin-left: -3px;width:70px; height: 32px;cursor:pointer; ">
                                    </label>
                                    <button type="button" tabindex="4"
                                            class="width-35 pull-right btn btn-sm btn-primary"
                                            id="btnSubmit" style="margin-right: 2px;">
                                        <i class="icon-key"></i>登陆
                                    </button>
                                </div>
                                <div class="clear clearfix" style="height:40px;">
                                    <label title="公共场所慎用,下次不需要再填写帐号">
                                        <div class="checkbox checkbox-primary">
                                            <input id="rememberac" class="styled" name="rememberac"
                                                   type="checkbox"/>
                                            <label for="rememberac" style="line-height: 16px;">
                                                记住账号
                                            </label>
                                        </div>
                                    </label>
                                    &nbsp;&nbsp;
                                    <label title="公共场所慎用,下次不需要再填写帐号和密码">
                                        <div class="checkbox checkbox-primary">
                                            <input id="rememberme" class="styled" name="rememberme" type="checkbox"/>
                                            <label for="rememberme" style="line-height: 16px;">
                                                自动登录(30天)
                                            </label>
                                        </div>
                                    </label>
                                </div>
                            </fieldset>
                        </form>
                        <div class="social-or-login center">
                            <span class="bigger-110">Java版</span>
                        </div>
                        <div class="social-login center">
                            首次加载，请耐心等待，本系统不再对IE8以下浏览器支持，请见谅。
                        </div>
                    </div>
                    <!-- /widget-main -->
                    <div class="toolbar clearfix">
                    </div>
                </div>
                <!-- /widget-body -->
            </div>
            <!-- /login-box -->
        </div>
        <!-- /position-relative -->
    </div>
</div>
<div class="loginbm">
    © 2020 All Rights Reserved. <a href="#">xinsite</a>
</div>
<strong></strong>
</body>
</html>
<script type="text/javascript">
    var cookie_name = "control_username", cookie_pwd = "control_password";
    $(document).ready(function () {
        if (window != top) top.location.href = location.href;
        if (location.href.indexOf("main") > 0) {
            //location.href = "/control/";
            location.href = "login.html";
        }
        loadRSAPublicKey();

        rememberInput();
        $("#validCode").val("1111");
        $("#username").val("admin");
        $("#password").val("111111");

        $('#btnSubmit').on('click', function () {
            if (publicKey) userLogin();
            else loadRSAPublicKey("userLogin()");
        });
        $(document).keypress(function (e) {
            var key = e.which; //e.which是按键的值
            if (key == 13) {
                if (publicKey) userLogin();
                else loadRSAPublicKey("userLogin()");
            }
        });

        $(".loginbody").height($(window).height() - 100);
        window.onresize = function () {
            var height = $(window).height() - $(".login-container").height() - 160;
            height = parseInt(height / 2);
            if (height < 15) height = 15;
            $("#top_title").attr("style", "margin-top:" + height + "px;");
            setTimeout(function () {
                //window.location.reload();
            }, 100);
        }
        $("#captcha_img").hide();
        setTimeout(function () {
            cacheLoadFileFn();
            if ($.getUrlVar('type') == 1) {
                Alert("该账号已经在其他地方登录，请重新登录！");
            } else {
                var off_msg = $.getUrlVar('off_msg');
                if (off_msg) {
                    off_msg = decodeURIComponent(off_msg);
                    Alert(decodeURIComponent(off_msg));
                }
            }
            $("#captcha_img").show();
            $("#captcha_img").attr("src", "imageKaptcha?t=" + Math.random());
        }, 200);
        window.onresize();
    });

    function changeVerifyCode(img) {
        img.src = "imageKaptcha?" + Math.floor(Math.random() * 100);
    }

    function rememberInput() {
        if ($.cookie(ck_names.remember_user)) {
            $("#username").val($.cookie(ck_names.remember_user));
            $("#rememberac").attr("checked", 'checked');
        }
        if ($.cookie(ck_names.remember_me)) {
            $("#rememberme").attr("checked", 'checked');
        }
    }

    function userLogin() {
        var username = $("#username").val();
        var password = $("#password").val();
        var validcode = $("#validCode").val();
        var rememberme = $("input[name='rememberme']").is(':checked');
        if (username == "") {
            $("#username").focus();
            Alert("请输入登录账号!");
        } else if (password == "") {
            $("#password").focus();
            Alert("请输入登录密码!");
        } else if (validcode == "") {
            $("#validCode").focus();
            Alert("请输入验证码!");
        } else {
            layer.load(0, {shade: [0.1, '#fff']});
            var len = password.length;
            var md5pwd = MD5(MD5(password).toUpperCase()).toLowerCase();
            if (publicKey) {
                var encrypt = new JSEncrypt();
                encrypt.setPublicKey(publicKey);
                md5pwd = encrypt.encrypt(md5pwd + validcode.toLowerCase());
            }
            $("#password").val(md5pwd.substring(0, len));
            $.ajax({
                type: "post", cache: false, dataType: "json",
                url: "login?t=" + Math.random(),
                data: {
                    username: username,
                    password: md5pwd,
                    validcode: validcode,
                    rememberme: rememberme
                },
                success: function (r) {
                    if (r.success) {
                        setTimeout(function () {
                            isReturnLogin = false;
                            $.cookie(ck_names.remember_user, $("#rememberac:checked").val() ? username : "");
                            $.cookie(ck_names.remember_me, rememberme ? rememberme : "");
                            //location.href = "main?t=" + Math.random();
                            location.href = "main";
                        }, 100);
                    } else {
                        Alert(r.msg);
                        loadRSAPublicKey();
                        $("#password").val(password);
                        $("#captcha_img").attr("src", "imageKaptcha?t=" + Math.random());
                    }
                    layer.closeAll('loading');
                }
            });
        }
    }

    function loadRSAPublicKey(back_fun) {
        $.ajax({
            type: "post", cache: false, dataType: "json",
            url: "publicKey?t=" + Math.random(),
            success: function (r) {
                if (r.success) {
                    publicKey = r.data;
                    if (typeof back_fun == "string") eval(back_fun);
                }
            }
        });
    }

    ///缓存预加载Js文件
    function cacheLoadFileFn() {
        if ($.cookie(ck_names.js_loaded) == "true") return;
        var host = window.location.hostname
        if (host.indexOf("localhost") == -1) {
            layer_index = layer.msg('更新加载，请耐心等待...', {
                time: 20000, icon: 16, shade: 0.1
            });
            setTimeout(function () {
                if (layer_index) {
                    if (layer_index) layer.close(layer_index);
                    $.cookie(ck_names.js_loaded, "true");
                }
            }, 8000);

            jQuery.ajaxSetup({cache: true}); //客户端缓存，调用js时后面的类似"?_=13126578"的参数去掉
            loadFileFn(["javascript/ajax_url.js"]);
            loadFileFn(["javascript/extjs4/ext-all.js"]);
            loadFileFn(["javascript/plugins/ueditor/ueditor.config.js"]);
            loadFileFn(["javascript/plugins/ueditor/ueditor.all.min.js"]);
            loadFileFn(["javascript/plugins/kindeditor/kindeditor-all.js"]);
            setTimeout(function () {
                jQuery.ajax({
                    type: "post", cache: false,
                    dataType: "json", async: true,
                    url: "anon/cachefile?t=" + Math.random(),
                    success: function (obj) {
                        if (obj.state) {
                            loadFileFn(obj.cssfiles);
                            loadFileFn(obj.jsfiles);
                            isLoadCompleted(obj.jsfiles.length);
                        } else {
                            Ext.getBody().unmask();
                            ErrorMessageBoxShow('部分组件加载失败');
                        }
                    }
                });
            }, 300);
        } else {
            if (layer_index) layer.close(layer_index);
        }
    }

    function loadFileFn(files) {
        if (files) {
            for (var i = 0; i < files.length; i++) {
                var name = files[i].replace(/^\s|\s$/g, "");
                var att = name.split('.');
                var ext = att[att.length - 1].toLowerCase();
                var isCSS = ext == "css";
                if (isCSS) {
                    $("<link>").attr({
                        rel: "stylesheet",
                        type: "text/css",
                        href: name
                    }).appendTo("head");
                } else {
                    jQuery.getScript(name, function (data, status, jqxhr) {
                        load_script_count++;
                    });
                }
            }
        }
    }

    //window.onerror = function () { return true; }
    var load_script_count = 0, layer_index;

    function isLoadCompleted(count) {
        if (load_script_count >= count - 10) {
            $.cookie(ck_names.js_loaded, "true");
            if (layer_index) layer.close(layer_index);
        } else {
            setTimeout(function () {
                isLoadCompleted(count);
            }, 500);
        }
    }

    function Alert(msg) {
        layer.alert(msg + "\r\n", {
            title: '提示框',
            icon: 0
        });
    }


    $.extend({
        getUrlVars: function () {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        },
        getUrlVar: function (name) {
            return $.getUrlVars()[name];
        }
    });

</script>